import java.io.IOException;
import java.net.SocketException;
import java.util.HashMap;

/**
 * Created with IntelliJ IDEA.
 * Description:udp字典服务器
 * Author: WJW
 * Date: 2024-08-25
 * Time: 15:05
 */
public class UdpDictServer extends UdpEchoServer{

    private HashMap<String,String> hashMap = new HashMap<>();

    public UdpDictServer(int port) throws SocketException {
        super(port);

        hashMap.put("cat","小猫");
        hashMap.put("dog","小狗");
        hashMap.put("hello","你好");
        hashMap.put("book","书本");
        //此处可无限添加英汉键值对
    }

    //start方法完全继承父类方法即可
    //process方法要重写，加入翻译业务

    @Override
    public String process(String request) {
        //参数是英文单词 返回值是对应的汉语
        return hashMap.getOrDefault(request,"您查找的单词不存在！");
    }

    public static void main(String[] args) throws IOException {
        UdpDictServer server = new UdpDictServer(9090);
        server.start();
    }
}
